home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / toadshr1.zip / TOADSHR1.PAS < prev   
Pascal/Delphi Source File  |  1989-06-14  |  36KB  |  1,012 lines

  1. PROGRAM ToadShar;
  2.  
  3. { Toad Hall Shar v1.1 for Turbo Pascal v5.0
  4.  
  5.   Other shars available for MS-DOS had no wildcard capability,
  6.   and I got BLOODY tired of typing in all those filenames!
  7.  
  8.   This one's got wildcard capability (both for shar creation and extraction).
  9.  
  10.   I've arbitrarily decided to force the world to accept the MS-DOS shar
  11.   file type of ".SHR" for a shar file type (when wildcard extracting)
  12.   (since we can't use the Unix ".shar" standard).
  13.  
  14.   You don't like it?  Recode it!
  15.  
  16.   No, I don't know how to change it for Turbo Pascal v4.0.
  17.  
  18.   Usage:
  19.     shar [-u] [file1]..[filen]
  20.  
  21.     Where file1..filen can be up to 20 MS-DOS path\filenames
  22.     (wildcarded if you wish).  (The 20 was arbitrary .. see MAXARGS.)
  23.  
  24.     -u     Unshar (extract) members from shar file(s).
  25.            Yes, the -u (any case) MUST be the first command line parameter!
  26.            shar filenames can be full DOS paths, with a default file
  27.            type of ".SHR" (added if required).
  28.  
  29.   During shar creation:
  30.     The .SHR files produced will be simplistic (e.g., none of the fancy
  31.     Unix switches are available).  However, they should be compatible
  32.     with Unix shars (provided you work around the line ending problem,
  33.     of course).
  34.  
  35.     Shar-formatted output is to StdOut (e.g., via redirection at the
  36.     DOS command line).  No check is made for an output file's existence
  37.     (naturally).  Output is standard DOS text file (e.g., CR/LF line
  38.     endings).
  39.  
  40.     No tests are made to filter out control characters, etc., and target
  41.     member files are treated as text files.  I would NOT suggest using
  42.     this shar on anything but pure Ascii text files!
  43.  
  44.     Any error msgs will go to StdOut (yep, the file you're creating!).
  45.     Sorry 'bout that .. don't wanna mess with a StdErr output routine
  46.     at this time.  Maybe later.
  47.  
  48.  
  49.   During extraction:
  50.  
  51.     You can wildcard the extracting.  (E.g., if you have FOO1.SHR and
  52.     FOO2.SHR, just enter "TOADSHAR FOO*" and both files will be unshared.)
  53.  
  54.     Existing files will NOT be overwritten!  You'll get a warning message,
  55.     and shar will continue to work its way through the remaining shar file
  56.     members (if any).
  57.  
  58.     No tests are made (to date) to replicate sed or sh errorchecking
  59.     (e.g., the simplistic character count).
  60.  
  61.     Some sed/sh "echo" commands are echoed to StdOut during extraction.
  62.  
  63.   I've tested TOADSHAR on Unix and MS-DOS .shar files created with various
  64.   switch settings .. seems to work ok.
  65.  
  66.   This sucker isn't ALL it could be yet .. could use more file read/write
  67.   error trapping, more sophisticated sh-like testing (char counts,
  68.   file overwriting, etc.) .. but it'll do for now.
  69.  
  70.   Credits:
  71.     Fancy dynamic arrays of FindFirst and FindNext SearchRecs,
  72.     thanks to a hack of:
  73.  
  74.     "Linked list modules from LINKLIST.PAS"
  75.     Copyright (c) 1985 by Alan D. Hull
  76.  
  77.     Boyer-Moore string searching (credits, source in POSBM.ASM)
  78.  
  79.     Released to the public domain.
  80.     Constraints:  Do NOT distribute without source and documentation.
  81.                   Do NOT remove credits.
  82.  
  83.     David P Kirschbaum
  84.     Toad Hall
  85.     kirsch@braggvax.ARPA
  86.     (or maybe kirsch%braggvax.ARPA@cacfs.army.mil)
  87.     (919) 868-3471 voice/data
  88.  
  89.     v1.0  Original release
  90.     v1.1  Added:
  91.             new posBM and posCH POS() replacements.
  92.             StdErr message output.
  93. }
  94.  
  95. {$B-}  {shortcut Boolean logic}
  96. {$D-}  {No debug info}
  97. {$F-}  {No far calls}
  98. {$L-}  {No local symbol info}
  99. {$R-}  {No range checking}
  100. {$S-}  {No stack checking .. taking a chance on this one
  101.         for systems with VERY limited memory ..
  102.         You don't like it?  Recompile it.}
  103. {$V-}  {Relaxed VAR string parm testing}
  104.  
  105. { DEFINE Debug}  {enable for some debug displays, file overwriting, etc.}
  106.  
  107. Uses Dos;  {for the Find First/Find Next stuff}
  108.  
  109. TYPE
  110.   Str20 = STRING[20];
  111.   Str80 = STRING[80];
  112.  
  113. CONST
  114.   QUOTE = #39;                      {single-quotation mark/apostrophe char}
  115.   MAXARGS = 20;                     {change as you like}
  116.   VERSION = 'v1.1';
  117.   CRLF : ARRAY[1..2] OF CHAR = #$0D#$0A;  {v1.1}
  118.  
  119. VAR
  120.   argv, argc : Byte;
  121.   Args : ARRAY[1..MAXARGS]          {array of cmdline parms}
  122.            OF PathStr;              {STRING[79]}
  123.  
  124.   InFile : TEXT;
  125.  
  126.  
  127. {
  128.  
  129. SearchRec, DirStr, NameStr, ExtStr are declared in the Dos unit.
  130.  As a reminder:
  131.  
  132.  TYPE SearchRec = RECORD
  133.                     fill : ARRAY[1..21] OF Byte;
  134.                     attr : Byte;
  135.                     time : longint;
  136.                     size : longint;
  137.                     Name : STRING[12];
  138.                   END;
  139. }
  140.     SrchRec : SearchRec;
  141.  
  142.     Dir : DirStr;                     {STRING[79]}
  143.     Name: NameStr;                    {STRING[8]}
  144.     Ext : ExtStr;                     {STRING[4]}
  145.  
  146. CONST
  147.  
  148.   {The shar file header (picked from a handy Unix speciman).
  149.   This array of array of chars is a kludge, I know .. but it was the
  150.   simplest/fastest way to collect one big hunk of characters for output.
  151.   Now if I wanted to add my block read/writes .. but then we wouldn't
  152.   have a nice neat TEXT file, would we?
  153.   }
  154. (*
  155.   Hdr1 : ARRAY[1..26] OF CHAR = '#    This is a shell archive.';
  156.   Hdr2 : ARRAY[1..53] OF CHAR =
  157. '#    Remove everything above and including the cut line.';
  158.   Hdr3 : ARRAY[1..43] OF CHAR =
  159. '#    Then run the rest of the file through sh.';
  160.   Hdr4 : ARRAY[1..57] OF CHAR =
  161. '#----cut here-----cut here-----cut here-----cut here----#';
  162.   Hdr5 : ARRAY[1..9] OF CHAR = '#!/bin/sh';
  163.   Hdr6 : ARRAY[1..25] OF CHAR = '# shar:    Shell Archiver';
  164.   Hdr7 : ARRAY[1..48] OF CHAR =
  165. '#    Run the following text with /bin/sh to create:';
  166. *)
  167.  
  168.   NR_HDRLINES = 4;
  169.   Hdr : ARRAY[1..NR_HDRLINES] OF Str80 =
  170.   (
  171. '#  This is a shell archive.'#$0D#$0A'# Remove everything above and including the cut ',
  172. 'line.'#$0D#$0A'# Then run the rest of the file through sh.'#$0D#$0A'#----cut here-----cut here',
  173. '-----cut here-----cut here----#'#$0D#$0A'#!/bin/sh'#$0D#$0A'# shar:    Shell Archiver',
  174. #$0D#$0A'# Run the following text with /bin/sh to create:'#$0D#$0A
  175.   );
  176.  
  177.  
  178. {Load our posBM and posCH modules}
  179.  
  180. {$F+}
  181. {$L POSBM}
  182.  
  183. FUNCTION posBM(Pat,Str : STRING) : BYTE; EXTERNAL;
  184.  
  185. {$L POSCH}
  186. FUNCTION posCH(Ch : CHAR; S : STRING) : BYTE; EXTERNAL;
  187.  
  188. {And our StdErr procedure}
  189. {$L STDERR}
  190.  
  191. PROCEDURE Write_StdErr(S : STRING); EXTERNAL;
  192. {$F-}
  193.  
  194. {
  195. (Linked list modules from LINKLIST.PAS)
  196.  Copyright (c) 1985 by Alan D. Hull
  197.  TURBO LinkList modules and descriptions are hereby donated to
  198.  the public domain. They may be included  in  any  other  free
  199.  software  without  royalties  to  the  author. TURBO LinkList
  200.  procedures,  descriptions  and/or  declarations  may  not  be
  201.  included  in  whole  or  in part in any program, function, or
  202.  package   sold  for  commercial  gain,  without  the  express
  203.  permission of the author.
  204.  
  205.  Thanks, Alan .. gee, 1985 .. sigh ..
  206. }
  207.  
  208.  
  209. TYPE
  210. { We don't really NEED the entire SearchRec saved (from a FindFirst
  211.   or FindNext) .. but I'm keeping it handy for now.
  212.   Actually, all we need is the Dir and SearchRec.Name (for opening
  213.   input files later).
  214. }
  215.   SrchRecPtr = ^node;
  216.  
  217.   node = RECORD                         { this is the linked list node }
  218.     flink,
  219.     blink   : SrchRecPtr;
  220.     SrchRec : SearchRec;                { map in a data record }
  221.     Dir     : DirStr;                   {remember the directory also}
  222.   END;
  223.  
  224. VAR
  225.   head, tail, curr, Temp  :   SrchRecPtr;
  226.  
  227.  
  228.  
  229. PROCEDURE Allocate_Node( VAR node_ptr: SrchRecPtr);
  230.   {  Allocate a node of a doubly-linked list  }
  231.   BEGIN
  232.     NEW (node_ptr);                     { get a new block of memory }
  233.     node_ptr^.flink := NIL;             { make sure it doesn't point to }
  234.     node_ptr^.blink := NIL;             { any other nodes yet. }
  235.   END;
  236.  
  237.  
  238. PROCEDURE Add_After_Node (VAR head, tail, current, newp: SrchRecPtr);
  239.   {  Add the node to the linked list
  240.      head    - A pointer to the first node in the linked list
  241.      tail    - A pointer to the last node in the linked list
  242.      current - A pointer to the node in the list that the new node
  243.                is to be added af